package com.peng.leetcode.array;

/**
 * NumEquivDominoPairs
 * 1128. 等价多米诺骨牌对的数量
 *
 * @author: lupeng6
 * @create: 2021/1/26 10:47
 */
public class NumEquivDominoPairs {

    public static void main(String[] args) {
        int[][] dominoes = {{1,2},{2,1},{3,4},{5,6}};
        System.out.println(new NumEquivDominoPairs().numEquivDominoPairs(dominoes));
    }

    public int numEquivDominoPairs(int[][] dominoes) {
        int count = 0;
        for (int i = 0; i < dominoes.length - 1; i++) {
            int[] dominoe = dominoes[i];
            int sum = dominoe[0] + dominoe[1];
            for (int j = i + 1; j < dominoes.length; j++) {
                int[] dominoe1 = dominoes[j];
                int tempSum = dominoe1[0] + dominoe1[1];
                if (tempSum != sum) {
                    continue;
                }
                if (dominoe[0] == dominoe1[0] && dominoe[1] == dominoe1[1]) {
                    count++;
                    continue;
                }
                if (dominoe[0] == dominoe1[1] && dominoe[1] == dominoe1[0]) {
                    count++;
                    continue;
                }
            }
        }
        return count;
    }
}
